import { UserModel } from "../model/UserModel";
import { MySqlUtil } from "../../engine/utils/MySqlUtil";
import { Logger } from "../../engine/utils/Logger";



export class UserDao {


    private static Sql_queryAllUser:string = "SELECT * FROM users;"
    private static Sql_queryUserById:string = "select * from users where userid=";

    public static insertUser(user:UserModel){
        // let dd:string = " INSERT INTO users values(null, 100002, "test2", "nickname2");"
    }

    public static queryUserById(userid:number){
        MySqlUtil.executeSql(this.Sql_queryUserById+userid, (isOk:boolean, result)=>{
            if(isOk){
                Logger.log("queryUserById===", result);

            }
        });
    }

    public static queryAllUsers(){
        MySqlUtil.executeSql(this.Sql_queryAllUser, (isOk:boolean, result)=>{
            if(isOk){
                for(let i=0; i<result.length; i++){
                    let model:UserModel = UserModel.createModel(result[i]);
                    UserModel.userList[i] = model;
                }
                Logger.log("queryAllUsers===", UserModel.userList);
            }
        });
    }
}